﻿using AutoMapper;
using MediatR;
using Traceability.App.API.Application.Command.Breed;
using Traceability.App.Domain.Traceability;
using Traceability.App.ErrorCode;
using Traceability.App.Infrastructrue.Interface;

namespace Traceability.App.API.Application.Handler.Breed
{
    public class GetBreedHandler : IRequestHandler<GetBreedCommand, APIResult<BreedingInformationModel>>
    {
        private readonly IBaseRepository<BreedingInformationModel> breedRepo;

        public GetBreedHandler(IBaseRepository<BreedingInformationModel> breedRepo)
        {
            this.breedRepo = breedRepo;
        }
        public Task<APIResult<BreedingInformationModel>> Handle(GetBreedCommand request, CancellationToken cancellationToken)
        {
            APIResult<BreedingInformationModel> result = new APIResult<BreedingInformationModel>();
            var res = breedRepo.GetAll().FirstOrDefault(x => x.Batch == request.Batch);
            result.Message = "显示成功";
            result.Data = res;
            result.Code = APIEnum.Ok;
            return Task.FromResult(result);
        }
    }
}
